package com.ruike.alisurface.ui.adapters;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ruike.alisurface.R;
import com.ruike.alisurface.bean.ShopInfoBean;
import com.voodoo.lib_utils.imageLoader.GlideImageLoader;

import java.util.List;

public class ShopinfoAdapter extends BaseQuickAdapter<ShopInfoBean.DataBean, BaseViewHolder> {


    Context mContext;

    public ShopinfoAdapter(@Nullable List<ShopInfoBean.DataBean> data, Context context) {
        super(R.layout.main_shopinfo_list_item, data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, ShopInfoBean.DataBean item) {
        ImageView productimg = helper.getView(R.id.productimg_img);
        TextView productname = helper.getView(R.id.productname_tv);
        TextView price = helper.getView(R.id.price_tv);
        helper.setText(R.id.spec_tv, item.getSpec() + "");

        if (TextUtils.isEmpty(
                item.getProductimg())) {
            GlideImageLoader.getInstance().loadImage(mContext,
                    R.drawable.zanwu_img
                    , productimg);
        } else {
            GlideImageLoader.getInstance().loadImage(mContext,
                    item.getProductimg()
                    , productimg);
        }

        helper.setText(R.id.manufacturer_tv, item.getManufacturer());
        productname.setText(item.getProductname());
        price.setText("￥ " + item.getPrice());
        if (item.isIs_remote()) {
            helper.getView(R.id.is_remote_tv).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.is_remote_tv).setVisibility(View.GONE);
        }
        if (item.isIs_insurance()) {
            helper.getView(R.id.is_insurance_tv).setVisibility(View.VISIBLE);

        } else {
            helper.getView(R.id.is_insurance_tv).setVisibility(View.GONE);
        }
        if (item.isIs_true_name()) {
            helper.getView(R.id.is_true_name_tv).setVisibility(View.VISIBLE);

        } else {
            helper.getView(R.id.is_true_name_tv).setVisibility(View.GONE);
        }

        if (item.isIs_prescription()) {
            helper.getView(R.id.is_true_prescription_tv).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.is_true_prescription_tv).setVisibility(View.GONE);
        }

        if (item.isIs_show_detail()) {
            helper.getView(R.id.product_details).setVisibility(View.VISIBLE);
        } else {
            helper.getView(R.id.product_details).setVisibility(View.INVISIBLE);
        }

        //获取当前item的position
        //int position = helper.getLayoutPosition();
    }
}

